#!/bin/bash
wait="#wait"
todo=$wait
last=""
while [ $todo != "#end" ]
do
  {
  echo '##################################'
  echo '1.wait...'
  sleep 1s
  rm runner.sh
  wget https://gitee.com/silencewing/remote_worker/raw/master/runner.sh
  echo '##################################'
  echo '2.fetch runner'
  todo=$(head -n +1 runner.sh)

  #if [ $todo == "#run" ]
  run=${todo:0:4}  #(expr match $todo "#run.*")
  # echo 'run'
  # echo $run
  if [ $run == "#run" ];
  then
  # echo 'last=todo'
  # echo $last
  # echo $todo
    if [[ $last == $todo ]];
    then
      echo '3.runner wait'
      sleep 60s
      continue
    else
      last=$todo
      # echo 'last=todo 2'
      # echo $last
      # echo $todo
      echo '##################################'
      echo '3.runner todo'
      
      message=${todo/'#run'/''}
      sh ./runner.sh $todo
    fi
  fi
  }||
  {
    echo '##################################'
    echo 'err'
  }
done
